import { ref } from 'vue'
import { defineStore } from 'pinia'
import type { UserInfo } from '@/types/user'
import UserService from '@/api/user'
import { useRoleStore } from './role'

export const useUserStore = defineStore('user', () => {
    const userinfoL = ref<UserInfo | undefined>()

    // 获取登录用户信息
    const getUserInfoL = async () => {
        const res = await UserService.getByToken()
        userinfoL.value = res

        const roleStore = useRoleStore()
        await roleStore.fetchRoles()
        await roleStore.setCurrentRole(res.role_id)
    }

    return { userinfoL, getUserInfoL }
})
